const app = getApp()
const request = require('../../../utils/https.js')
var fromUser, userId;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    indicatorDots: true,
    vertical: false,
    autoplay: true,
    interval: 3000,
    duration: 1000,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const that = this;
    userId = wx.getStorageSync('userId');
    let cid = options.cid;
    let cname = options.cname;
    wx.setNavigationBarTitle({
      title: cname
    })


    // that.setData({
    //   url: options.url,
    //   urlId: fastId
    // })
    that.pullProds(cid,userId);
  },

  pullProds(cateId, userId) {
    const that = this;
    //商品列表
    request._get(getApp().Api_url + 'brand/prodByCate', { //商品列表接口
      cateId: cateId,
      userId: userId,
      pageNum: 1,
      pageSize: 1000
    }, function (res) {
      if (res.data.errMsg == 'OK') {
        var dataList = res.data.data;
        that.setData({
          dataList: dataList,
          goodsList: dataList
        })

      }
    }, function () {})
  },

  //查看详情页
  goDetails(e) {
    const that = this;

    let userId = wx.getStorageSync("userId");
    if (userId == '' || userId == null || userId == 'undefined') {
      wx.reLaunch({
        url: '/pages/login/login?path=/pages/list/list'
      })
      return;
    }
    let goodsId = e.currentTarget.dataset.goodsid;
    let fast = e.currentTarget.dataset.fast;
    wx.navigateTo({
      url: '/pages/gift_details/gift_details?goodsId=' + goodsId + '&show=' + 0 + '&userId=' + fromUser + '&fast=' + fast
    })
  },
  //详情页拉起购物车
  goShopping(e) {
    const that = this;
    let userId = wx.getStorageSync("userId");
    if (userId == '' || userId == null || userId == 'undefined') {
      wx.reLaunch({
        url: '/pages/login/login?path=/pages/list/list'
      })
      return;
    }
    let goodsId = e.currentTarget.dataset.goodsid;
    let goodsType = e.currentTarget.dataset.kinds;
    let fast = e.currentTarget.dataset.fast;

    wx.navigateTo({
      url: '/pages/gift_details/gift_details?goodsId=' + goodsId + '&show=' + 1 + '&userId=' + fromUser + '&fast=' + fast
    })
  },


  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  /*   onPullDownRefresh: function () {

    }, */

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
    const that = this;
    if (res.from === 'button') {
      // 来自页面内转发按钮

      return {
        title: '快美甄选',
        path: '/packageB/pages/prodCate/prodCate?urlId=' + that.data.urlId + '&url=' + that.data.url + '&userId=' + userId
      }
    } else {
      return {
        title: '快美甄选',
        path: '/packageB/pages/prodCate/prodCate?urlId=' + that.data.urlId + '&url=' + that.data.url + '&userId=' + userId
      }
    }
  }
})